package com.wnxy.consumer.listener;
import org.springframework.amqp.core.Message;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DeadListener {

    // Channel  连接MQ的 通道
    @RabbitListener(queues = "dlx.queue")
    public void handle(String msg, Channel channel, Message message) throws IOException {
        //消息的属性对象
        MessageProperties properties = message.getMessageProperties();
        //消息的唯一标识
        long deliveryTag = properties.getDeliveryTag();

        System.out.println("我是死信消费者 ===> " + msg);

        //手动应答 (ack  应答完毕后 queue中的消息会删除 )
        channel.basicAck(deliveryTag, false);
    }

}